#include <iostream>
#include <string>
#include <vector>

// Simple record structure
struct Record {
    int id;
    std::string data;
    bool is_deleted;

    Record(int record_id = 0, const std::string &record_data = "")
        : id(record_id), data(record_data), is_deleted(false) {}
};

// Simple table structure
struct Table {
    std::string name;
    std::vector<Record> records;

    Table(const std::string& table_name) : name(table_name) {}
};

// Simple database manager
class SimpleDB {
private:
    std::vector<Table> tables_;

public:
    SimpleDB() {
        std::cout << "SimpleDB initialized" << std::endl;
    }

    bool createTable(const std::string& table_name) {
        for (const auto& table : tables_) {
            if (table.name == table_name) {
                std::cout << "Table already exists" << std::endl;
                return false;
            }
        }
        tables_.push_back(Table(table_name));
        std::cout << "Table '" << table_name << "' created" << std::endl;
        return true;
    }

    bool insertRecord(const std::string& table_name, const Record& record) {
        for (auto& table : tables_) {
            if (table.name == table_name) {
                table.records.push_back(record);
                std::cout << "Record inserted into '" << table_name << "'" << std::endl;
                return true;
            }
        }
        std::cout << "Table not found" << std::endl;
        return false;
    }

    std::vector<Record> getRecords(const std::string& table_name) {
        for (const auto& table : tables_) {
            if (table.name == table_name) {
                return table.records;
            }
        }
        return {};
    }
};

void printMenu() {
    std::cout << "\n====================" << std::endl;
    std::cout << "Simple Database Demo" << std::endl;
    std::cout << "====================" << std::endl;
    std::cout << "1. Create table" << std::endl;
    std::cout << "2. Insert record" << std::endl;
    std::cout << "3. Show records" << std::endl;
    std::cout << "0. Exit" << std::endl;
    std::cout << "Choice: ";
}

int main() {
    std::cout << "Starting Simple Database Demo..." << std::endl;

    SimpleDB db;
    int choice;

    do {
        printMenu();
        std::cin >> choice;

        switch (choice) {
            case 1: {
                std::string table_name;
                std::cout << "Enter table name: ";
                std::cin >> table_name;
                db.createTable(table_name);
                break;
            }
            case 2: {
                std::string table_name;
                int id;
                std::string data;
                std::cout << "Enter table name: ";
                std::cin >> table_name;
                std::cout << "Enter ID: ";
                std::cin >> id;
                std::cout << "Enter data: ";
                std::cin.ignore();
                std::getline(std::cin, data);
                Record record(id, data);
                db.insertRecord(table_name, record);
                break;
            }
            case 3: {
                std::string table_name;
                std::cout << "Enter table name: ";
                std::cin >> table_name;
                auto records = db.getRecords(table_name);
                std::cout << "Records in '" << table_name << "':" << std::endl;
                for (const auto& record : records) {
                    if (!record.is_deleted) {
                        std::cout << "ID: " << record.id << ", Data: " << record.data << std::endl;
                    }
                }
                break;
            }
            case 0:
                std::cout << "Goodbye!" << std::endl;
                break;
            default:
                std::cout << "Invalid choice" << std::endl;
        }

        if (choice != 0) {
            std::cout << "\nPress Enter to continue...";
            std::cin.ignore();
            std::cin.get();
        }

    } while (choice != 0);

    return 0;
}
